<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | User Info </title>
<?php include_once("common_script_inclusions.php"); ?>
</head>

<body>
<?php
require_once("includes/pagetop.php");
if(isset($_SESSION['Allyfolio_User_ID']))
{   
    if($_SESSION['Allyfolio_User_ID']<0){
        redirect("accountblocked.php");    
    }
}
else{
    redirect("index.php");
}
include_once("updates/CommonFeatures.php");


if(isset($Alluserphone) && $Alluserphone!="" && isset($action) && ($action=="forgot" || $action=="resend"))
{
    $Alluserphone=sanitize($Alluserphone);
    
    $userinfoqry="select User_ID,Email_ID,Full_Name,Secondary_Email_ID from af_users where (Email_ID=:Email_ID or Mobile_Number=:Mobile_Number) ";
    $userinfo=$pdodbobj->fetch_array($pdodbobj->query($userinfoqry,array(":Email_ID"=>$Alluserphone,":Mobile_Number"=>$Alluserphone)));
        
    if(count($userinfo)>0)
    {
        require_once"includes/mailscript.php";
        
        $randomstring=random_string(20);
        
        $updatestring=array();
        $conditionarr=array();
        $conditionarr["User_ID"]=$userinfo[0]['User_ID'];
        $updatestring["Verify_Random_String"]=$randomstring;
        
        $emailid=$userinfo[0]['Email_ID'];
        if(isset($userinfo[0]['Secondary_Email_ID']) && trim($userinfo[0]['Secondary_Email_ID'])!='')
        {
            $emailid=$userinfo[0]['Secondary_Email_ID'];
        }
        
        $subject="Recover Password to Allyfolio Social Portal.";
        
        $bodymessage="
        <table cellspacing='2' cellpadding='2' width='100%'>
            <tr>
                <td>
                Hi ".$userinfo[0]['Full_Name'].",<br/><br></td>
            </tr>
            <tr>
                <td>
                    You have requested for changing your allyfolio account password. 
                 </td>
            </tr>
            <tr>
                <td>
                Please click on below link to reset your account password & continue with Allyfolio.<br>
                <a href='".WEBURL."resetpass.php?actcode=".$randomstring."' target='_blank'>".WEBURL."resetpass.php?actcode=".$randomstring."</a>
                </td>    
            </tr>
            <tr>
                <td>
                <br/>
                <br/>
                   Thanks,<br/>Allyfolio Support Team.
                </td>
            </tr>       
        </table>" ;  
        
        $pdodbobj->updateData("af_users",$updatestring,$conditionarr);
        if($pdodbobj->affectedrows>0)
        {
            if(sendMail($emailid,$subject,$bodymessage,$headers))
            {
                $passwordsendmsg="An email is sent to your registered Email id with reset password link. Please use that link to reset your password.";
            }
            else
            {
                $errormsg="There is an error in sending reset password email to your account.";
                
            }
            
        }
    }
    else
    {
        $errormsg="Please enter correct Email ID or Phone Number.";
    }
}

$loggedUserObj=new UserDetails();
if (!isset($_SESSION["User_details"])){
    $_SESSION["User_details"]=$loggedUserObj->getUserDetails($_SESSION["Allyfolio_User_ID"],true);
}
$loggedUserObj=$_SESSION["User_details"];
//echo "<pre>";
//print_r($loggedUserObj);
//echo date("Y-m-d",1412467200);
//$date = new DateTime("2014-10-05");
// "-2209078800"
//echo $date->format("U");

/*

SELECT email_id, DATE_FORMAT(DOB,'%m') as dob_month,DATE_FORMAT(DOB,'%d') as dob_d 
,DATE_FORMAT(UTC_TIMESTAMP(),'%m') as utc_m,DATE_FORMAT(UTC_TIMESTAMP(),'%d') as utc_d
,
(DATE_FORMAT(DOB,'%d')-DATE_FORMAT(UTC_TIMESTAMP(),'%d')) as dleft
FROM af_users 
where 
DATE_FORMAT(DOB,'%m')=DATE_FORMAT(UTC_TIMESTAMP(),'%m')
and 
(DATE_FORMAT(DOB,'%d')-DATE_FORMAT(UTC_TIMESTAMP(),'%d'))<=1




select  
 u.email_id
,DATE_FORMAT(u.DOB,'%m') as dob_month
,DATE_FORMAT(u.DOB,'%d') as dob_d 
,DATE_FORMAT(UTC_TIMESTAMP(),'%m') as utc_m
,DATE_FORMAT(UTC_TIMESTAMP(),'%d') as utc_d
,(DATE_FORMAT(u.DOB,'%d')-DATE_FORMAT(UTC_TIMESTAMP(),'%d')) as dleft

from af_users as u,af_user_friends as af_frnd
where u.user_id=af_frnd.user_friend_id 
and af_frnd.user_id=MineUserID 
and af_frnd.status in(1)
and
DATE_FORMAT(u.DOB,'%m')=DATE_FORMAT(UTC_TIMESTAMP(),'%m')
and 
(DATE_FORMAT(u.DOB,'%d')-DATE_FORMAT(UTC_TIMESTAMP(),'%d'))<=1
*/
?>
<script type="text/javascript" src="js/bday-picker.min.js"></script> 
<script type="text/javascript">
    
$(document).ready(function(){
    /*
    $("#dobpicker").birthdaypicker({
        defaultDate: "<?php echo (strlen($loggedUserObj->dob)>4)?date("Y-m-d",$loggedUserObj->dob):date("Y-m-d"); ?>"
    });
    */
    
    /* for demo purpose 
    $("#picker2").birthdaypicker({
      futureDates: true,
      maxYear: 2020,
      maxAge: 75,
      defaultDate: "10-17-1980"
    });
    $("#picker3").birthdaypicker({
      dateFormat: "bigEndian",
      monthFormat: "long",
      placeholder: false,
      hiddenDate: false
    });*/
  });
</script>

	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<div class="wrapper row1">
	<div class="header">
    	<div class="log_button">
		<table width="744" border="0" style="margin-top:5px;">
			<tr>
				<td width="24">
					<a href="#"><img src="images/navico_1.png" /></a>				</td>
				<td width="36">
					<a href="#"><img src="images/navico_2.png" /></a>				</td>
				<td width="26">
					<a href="#"><img src="images/navico_3.png" /></a>				</td>
				<td width="30">
					<a href="#"><img src="images/navico_4.png" /></a>				</td>
					<td width="594">
					<!--<ul class="dn_txt3">
						<li><img src="images/dna_txt_right.png" /></li>
						<li><input type="text" class="dna_txt2" /></li>
						<li><img src="images/dna_txt_left.png" /></li>
					</ul>-->
					
					</td>
			</tr>
		  </table>
		</div>
		
       
    	
        <a href="index.html" class="logo"></a>
    </div>
    <div class="clearfix"></div>  
    
    
    </div>
    <div class="clearfix"></div>
    <!--=================Header end=======================-->
    
    
    
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
      <div class="header acSetting">
          <h1>Settings</h1>
     <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td style="vertical-align: top;">
                          <div >
                          <?php  
                          include_once("settings_menu.php");
                          
                          ?>
                          </div>
                    </td>
                    <td style="vertical-align: top;">
                        <form name="frmupdateusers" id="frmupdateusers" action="ajax/generic_crudoperations.php">
                            <div class="acSettingSecR">
                                 <div class="fieldSec">
                                    <label>User Name</label> <input type="text" name="first_name" id="first_name" placeholder="First" value="<?php echo $loggedUserObj->first_name;  ?>"/> <input type="text" name="last_name" id="last_name" placeholder="Last" value="<?php echo $loggedUserObj->last_name;  ?>"/>
                                 </div>
                                 <div class="fieldSec">
                                    <label>Display Name</label> <input name="display_name" id="display_name" type="text" placeholder="Name" value="<?php echo $loggedUserObj->profileName;  ?>"/>
                                 </div>
                                 <!--
                                 <div class="fieldSec">
                                    <div style="float: left;">
                                        <label>Date Of Birth</label> 
                                    </div>
                                    <div style="float: left;">
                                        <div class="picker" id="dobpicker"></div>
                                    </div>
                                    
                                 </div>
                                 -->
                                 <div class="fieldSec">
                                    <label>Primary E-mail</label> <input name="pemail" id="pemail" type="text" placeholder="E-mail" value="<?php echo $loggedUserObj->emailId;  ?>"/>
                                 </div>
                                 <div class="fieldSec">
                                    <label>Recovery E-mail</label> <input name="semail" id="semail" type="text" placeholder="E-mail" value="<?php echo $loggedUserObj->recovery_email;  ?>"/>
                                 </div>
                                 <div class="fieldSec">
                                    <label>Password</label> <input name="current_pwd" id="current_pwd" type="password" placeholder="Current Password"/> <strong>Current Password</strong> <a class="forgot" href="#" onclick="return showhideforgot('forgot');" style="margin-left:25px;"><strong>Forget Your Password?</strong></a>
                                 </div>
                                 <div class="fieldSec">
                                    <label></label> <input name="pwd" id="pwd" type="password" placeholder="New Password"/> <strong>New Password</strong>
                                 </div>
                                 <div class="fieldSec">
                                    <label></label> <input name="vpwd" id="vpwd" type="password" placeholder="Verify New Password"/> <strong>Verify New Password</strong>
                                 </div>
                                  <div class="fieldSec">
                                    <label>Location</label> <input name="location" id="location" type="text" placeholder="Location.." value="<?php echo $loggedUserObj->address;  ?>"/>
                                 </div>
                                 <div class="fieldSec">
                                    <label></label> <input name="cmdsave" id="cmdsave" type="submit" value="Save Changes"/> 
                                    <input type="button" id="cmdcancel" name="cmdcancel" value="Cancel" onclick="return resetMe();"/> 
                                 </div>
                                <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
                            </div>
                        </form>
                     
                </td>
                </tr>
                </table>
     
     </div>
     </div>
     
    <div class="clearfix"></div>
    
      
    
</div>
<div id="toPopup"> 
    	
        <div class="close" onclick="closePopup();"></div>
        <div id="popup_content" >  
            <div class="forgetPass">
            
              <h3>Forget Password</h3>
              <?php
            if(isset($errormsg) && $errormsg!="")
            {
                ?>
                <div class="errormsg" ><?php echo $errormsg; ?><br /><br /></div>
                <?php
            }
            ?>
                  <label>Enter your E-mail / User ID</label>
                  <input type="text" name="Alluserphone" id="forgotusername" placeholder="Enter your E-mail / User ID" /> 
                  <p>Your password will be sent to your E-mail & you can check 
                your password on your mail account. You may also contact to
                our help center for any issue.</p>
                
                <div class="btns"><input type="submit" value="Submit" id="forgotpassbtn" /> &nbsp; <input type="button" value="Cancel" class="simplebutton" onclick="return closePopup();" /></div>
              
              </div>        
        </div>
        <div id="fsentcontent" style="display: none;">  
            <div class="forgetPass">
              <h3>Forget Password</h3>
                <p>Your password has been sent to your E-mail & you can check 
            your password on your mail please. If your password not
            delivered on your mail you can resend again.</p>
            <input type="hidden" name="resenduserphone" value="<?php if(isset($Alluserphone)&& $Alluserphone!=""){ echo $Alluserphone; } ?>" />
            <div class="btns"><input type="submit" value="Resend"  id="resendpassbtn" /> &nbsp; <input type="button" value="Cancel" class="simplebutton" onclick="return closePopup();" /></div>
              
              </div>            
        </div>
        </div>
        	<div class="loader"></div>
   	<div id="backgroundPopup"></div>
    <input type="hidden" name="action" id="action" />
<script>

$("#forgotpassbtn").click(validateForgotPass);
    
    function validateForgotPass()
    {
        if(trim(document.getElementById('forgotusername').value)=="")
        {
            alertify.alert("Please enter either email id or phone number.");
            document.getElementById('forgotusername').focus();
            return false;
        }
        else
        {
            document.getElementById('action').value="forgot";
            return true;
        }
    }
    
    $("#resendpassbtn").click(validateResendPass);
    
    function validateResendPass()
    {
        
        document.getElementById('action').value="resend";
        return true;
        
    }
    
    function showhideforgot(action)
    {
        if(action=="forgot")
        {
            document.getElementById('popup_content').style.display='';
            document.getElementById('fsentcontent').style.display='none';
        }
        else
        {
            document.getElementById('popup_content').style.display='none';
            document.getElementById('fsentcontent').style.display='';
        }
        showpopup();
    }
    
    <?php
    if(isset($passwordsendmsg) && $passwordsendmsg!="")
    {
        ?>
        showhideforgot('resend');
        <?php
    }
    ?>
    
    <?php
    if(isset($errormsg) && $errormsg!="")
    {
        ?>
        showhideforgot('forgot');
        <?php
    }
    ?>
    
function resetMe(){
    window.location.reload();    
}

$( "#frmupdateusers" ).submit(function( event ) {
    var formS = document.getElementById("frmupdateusers");
    var urlstr = $("#frmupdateusers").attr( "action" );
    // Send the data using post
    $.ajax({
	  	type: "POST",
	  	url: urlstr,
	  	cache: false,
	  	data: { 
	  	         "actiontype":"update_user_settings",   
	  	         "first_name": document.getElementById('first_name').value,                                     
                 "last_name": document.getElementById('last_name').value,
                 "display_name": document.getElementById('display_name').value,
                 "pemail": document.getElementById('pemail').value,
                 "semail": document.getElementById('semail').value,
                 "pwd": document.getElementById('pwd').value,
                 //"dob":document.getElementById('birthdate').value,
                 "location": document.getElementById('location').value
              } 
    })
	.done(function( data ) {	
	   //alert(data);
	   var jsonParsed=$.parseJSON(data);
        console.log(jsonParsed);
        /*if(document.getElementById("errconsole")){
            document.getElementById("errconsole").innerHTML=data;
        }*/
        if(!isNaN(jsonParsed.err)){ //means have some code
            switch(parseInt(jsonParsed.err)){
                case 200:
                        alert(jsonParsed.msg);
                        break;
                default:
                        alert(jsonParsed.msg);
                        break;
            }
        }
	})
	.fail(function(msg) { 
		console.log(msg);
//		alert("error"); 
	})
    .always(function() { 
		//alert("complete"); 
	});
    return false;    

});
</script>
 </body>
</html>
